var overtimeApplyListUrl = basePath + "/sys/report/overtimeApply/list";
var dataGrid;
var schoolId = $("#userSchoolId").val();

$(function() {
	initSchoolIdValue();
	loadData();
});

function loadData() {
	dataGrid = $('#notice').datagrid({
		url : overtimeApplyListUrl,
		toolbar: '#tb',
		fit : true,
		fitColumns : true,
		border : true,
		pagination : true,
		idField : 'id',
		pageSize : config.pageSize,
		autoRowHeight : 140,
		pageList : config.pageList,
		queryParams : {
			approvalStatus: $("#approvalStatus").val(),
			applyTimeQuery: $("#applyTimeQuery").val(),
			approvalTimeQuery: $("#approvalTimeQuery").val(),
			schoolId: schoolId
		},
		nowrap : true,
		striped : true,
		rownumbers : true,
		columns : [ [  
		{
			field : 'id',
			align : "center",
			checkbox : true
		}, 
		{ 
			field : 'depart',
			title : '部门',
			width : 10,
			resizable : true,
			align : "center"
		}, 
		{
			field : 'overtimeReason',
			width : 20,
			title : '加班事由',
			align : "center",
			editor:{type:'validatebox',options:{required:true}}
		},
		{
			field : 'overtimePeople',
			title : '加班人',
			width : 10,
			align : "center",
			editor:{type:'validatebox',options:{required:true}}
		},
		{
			field : 'overtimeHours',
			title : '加班时长',
			width : 10,
			align : "center"
		},
		{
			field : 'startTime',
			title : '加班开始时间',
			width : 20,
			align : "center",
			formatter : function(value,row,index){
				return getTime(value,'yyyy-MM-dd hh:mm');
			},
		},
		{
			field : 'endTime',
			title : '加班结束时间',
			width : 20,
			align : "center",
			formatter : function(value,row,index){
				return getTime(value,'yyyy-MM-dd hh:mm');
			},
		},
		{
			field : 'applyer',
			title : '申请人',
			align : "center",
			width : 10
		},
		{
			field : 'applyTimeText',
			title : '申请时间',
			width : 10,
			align : "center"
		},
		{
			field : 'approver',
			title : '审批人',
			align : "center",
			width : 10
		},
		{
			field : 'approvalTimeText',
			title : '审批时间',
			align : "center",
			width : 10
		},
		{
			field : 'approvalStatusText',
			title : '审批状态',
			width : 10,
			align : "center"
		},
		{
			field : 'rejectReason',
			title : '驳回原因',
			width : 20,
			align : "center"
		},
		{
			field : 'remark',
			title : '备注',
			width : 20,
			align : "center"
		}
		]],
		onAfterEdit : function(rowIndex, rowData, changes){
			if(rowData.id){
				changes.id = rowData.id;
				changes.resourceRange = $("#resourceRange").val();
				changes.schoolId = schoolId;
				addmodify(changes);
			}else {
				rowData.resourceRange = $("#resourceRange").val();
				rowDate.schoolId = schoolId;
				addmodify(rowData);
			}
		}
	});
}
function reload() {
	dataGrid.datagrid("clearSelections");
	searchForm("searchForm");
}

function searchForm(formId) {
	dataGrid.datagrid('load', $.serializeObject($('#' + formId)));
}
function resetForms(formId) {
	$("#" + formId)[0].reset();
	$("#applyStartDate").datebox('setValue', '');
	$("#applyEndDate").datebox('setValue', '');
}

function exportToExcel(searchForm,exportUrl) {
	$("#" + searchForm).attr('action',exportUrl);
	$("#" + searchForm).submit();  
}

